package com.springboot.ww.platform.pd.order.demo;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import com.springboot.ww.platform.pd.order.constant.PdApiConstants;
import com.springboot.ww.platform.pd.dto.AuthParamValueVO;
import com.springboot.ww.platform.pd.dto.PdStoreTokenVO;
import com.springboot.ww.platform.pd.http.PdHttpProxy;
import com.springboot.ww.platform.pd.order.api.*;
import com.springboot.ww.platform.pd.order.service.impl.PdProxyImpl;
import com.springboot.ww.platform.pd.util.SignUtil;
import com.ww.springboot.boot.utils.DateUtil;
import com.ww.springboot.boot.utils.Func;
import com.ww.springboot.boot.utils.json.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.HttpGet;

import java.util.*;
import java.util.concurrent.ExecutionException;

import static cn.hutool.core.util.ClassUtil.isSimpleValueType;


/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2024-05-23 16:01
 */
@Slf4j
public class PdddTest {

    //private static final String US_URL = "https://openapi-b-global.temu.com/openapi/router";
    private static final String US_URL = "https://openapi-b-us.temu.com/openapi/router";
    private static final String CN_URL = "https://openapi.kuajingmaihuo.com/openapi/router";

    public final static String US_DOMAIN = "openapi-b-us.temu.com";
    public final static String US_OTHER_DOMAIN = "openapi-b-global.temu.com";


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String ss = "{\n" +
                "            \"authId\": \"1866784015316914178\",\n" +
                "            \"platformCode\": \"PD\",\n" +
                "            \"siteCode\": null,\n" +
                "            \"name\": \"Miyasudy\",\n" +
                "            \"code\": \"pinduoduo_0JZT\",\n" +
                "            \"storeStatus\": 1,\n" +
                "            \"token\": \"upso5limsthybdy5uvmngikruyllnf9nuz8wr7ddicvdgmdzjrj4vjbaekn\",\n" +
                "            \"paramMap\": {\n" +
                "                \"doMain\": \"openapi-b-global.temu.com\",\n" +
                "                \"appKeyCn\": \"37ba0eb620f8fd60f813e7577164aed4\",\n" +
                "                \"tokenCn\": \"wywo9ty85a2thctss61oh1jan2rvriwd7wxdqslfuagm1kqn7slumir9\",\n" +
                "                \"tokenGlobal\": \"\",\n" +
                "                \"currency\": \"USD\",\n" +
                "                \"appSecretCn\": \"6b33f33f96b8a5b0b33c7592b318442b3574b2b4\",\n" +
                "                \"appSecret\": \"27e82cc4e086fcc23fe664e9b14e244026b5d90e\",\n" +
                "                \"appKey\": \"870401b7ac1aefd1bb59bc7a45d646b9\"\n" +
                "            },\n" +
                "            \"apiUrl\": \"4.242.79.188\"\n" +
                "        }";
        //System.out.println(ss);
        AuthParamValueVO authParamValueVO = JsonUtil.parse(ss, AuthParamValueVO.class);
        PdStoreTokenVO storeVO = PdStoreTokenVO.builder().apply(authParamValueVO);
        storeVO.setRealDoMain(US_DOMAIN);
//        //PdGrabListReq pdGrabListReq = new PdGrabListReq(DateUtil.addDay(new Date(), -10), DateUtil.addDay(new Date(), -9));
//        //new PdProxyImpl(null).getOrderList(pdGrabListReq,storeVO);
//        //getSignCompany(storeVO);
//        methodSign2(storeVO);
        //orderList(storeVO);//区分站点
        //receiver(storeVO);//暂时不区分站点
        //good(storeVO);
        //WH-04883221708951571
//        storeVO.setRealDoMain(US_DOMAIN);
        warehouse(storeVO);
//        storeVO.setRealDoMain(US_OTHER_DOMAIN);
        //warehouse(storeVO);
        //goodUS(storeVO);
//        goodSku(storeVO);
       //optimize(storeVO);//暂时不区分站点
//        forecast(storeVO);
        //getForecast(storeVO);
        //getLabel(getLabelUrl(storeVO),storeVO);
//        forecastUpdate(storeVO);
          //detail(storeVO);//区分站点
//        shipmentGet(storeVO);
//        shipmentGet(storeVO);
//        shipmentGet(storeVO);
//        shipmentGet(storeVO);
//        shipmentGet(storeVO);
        //markUpdate(storeVO);
//        price(storeVO);
//        getCarrierId(storeVO);
        //accessInfo(storeVO);
        //goodPrice(storeVO);
        //orderPrice(storeVO);
        //unShippedList(storeVO);
        //packageConfirm(storeVO);

//        for (int i = 0; i < 20; i++) {
//            new Thread(()->{
//                String body = "{\"access_token\":\"ups1rftj5yqbk7mhvwsysjkqrovwc7xbr6dhy7a8e82kyejhtofmpmbiuz8\",\"app_key\":\"0aca3f449dee06086a36fe0cc8624f11\",\"data_type\":\"JSON\",\"pageNumber\":1,\"pageSize\":\"100\",\"sign\":\"A4BFA90F7A84A503065845BF79F4098C\",\"timestamp\":1726818034,\"type\":\"bg.order.list.get\",\"updateAtEnd\":1726818034,\"updateAtStart\":1726816834}";
//
//                String resultResp = postUS("52.175.245.142", body);
//                System.out.println(resultResp);
//            }).start();
//
//            new Thread(()->{
//                String body = "{\"access_token\":\"pe40yowhdotgoamn3jmjajjpsxa7klru1in7b1avjfijvlsveuz0o4vb\",\"app_key\":\"1e571af671a39e093739cde07796dc3b\",\"data_type\":\"JSON\",\"sendRequestList\":\"[{\\\"carrierId\\\":960246690,\\\"trackingNumber\\\":\\\"9214490357608913151567\\\",\\\"orderSendInfoList\\\":[{\\\"quantity\\\":1,\\\"orderSn\\\":\\\"211-09084056865910751\\\",\\\"parentOrderSn\\\":\\\"PO-211-09084041137270751\\\",\\\"goodsId\\\":601099649681656,\\\"skuId\\\":17592716169860}]}]\",\"sendType\":\"0\",\"sign\":\"E66C283B88483CE7A624C0E4630CA8BE\",\"timestamp\":1726818125,\"type\":\"bg.logistics.shipment.confirm\"}";
//
//                String resultResp = postUS("4.242.79.188", body);
//                System.out.println(resultResp);
//            }).start();
//        }
        //unShippedList(storeVO);//暂不区分
    }

    private static void orderPrice(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("parentOrderSn", "PO-211-01871711037992298");

        usToken(map, storeVO, "bg.order.amount.query");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);

    }

    private static void unShippedList(PdStoreTokenVO storeVO) {
        List<PdUnShipPackageResp.ResultDTO.UnshippedPackageDTO> unShipPackageResp = new PdProxyImpl().getUnShipPackageResp(storeVO);
        System.out.println(unShipPackageResp.size());
        System.out.println(JsonUtil.toJson(unShipPackageResp));
    }

    private static void packageConfirm(PdStoreTokenVO storeVO) {
        PdShippedConfirmReq pdShippedConfirmReq = new PdShippedConfirmReq();
        pdShippedConfirmReq.setPackageSn("PK-2472734212751511310");
        pdShippedConfirmReq.setTrackingNumber("1ZGH1263YN66665180");
        PdShippedConfirmReq.PackageDetailDTO packageDetailDTO = new PdShippedConfirmReq.PackageDetailDTO();
        packageDetailDTO.setQuantity(2);
        packageDetailDTO.setOrderSn("211-06919455214710117");
        packageDetailDTO.setParentOrderSn("PO-211-06919431621750117");
        pdShippedConfirmReq.setPackageDetail(Arrays.asList(packageDetailDTO));
        Map<String, Object> map = new TreeMap<>();
        map.put("packageSendInfoList", Arrays.asList(pdShippedConfirmReq));
        usToken(map, storeVO, PdApiConstants.SHIPPED_PACKAGE_CONFIRM);
        String req = JsonUtil.toJson(map);
        String resultResp = postUS(storeVO, req);
        System.out.println(resultResp);
    }

    private static void goodPrice(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("productSkuIds", Arrays.asList(8666188848L));
        cnToken(map, storeVO, "bg.goods.price.list.get");
        String s = JsonUtil.toJson(map);
        System.out.println(s);
        String body = HttpRequest.post(CN_URL).body(s).execute().body();
        System.out.println(body);
    }

    private static void accessInfo(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        usToken(map, storeVO, "bg.open.accesstoken.info.get");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);

        Map<String, Object> mapCn = new TreeMap<>();
        cnToken(mapCn, storeVO, "bg.open.accesstoken.info.get");
        String body = HttpRequest.post(CN_URL).body(JsonUtil.toJson(mapCn)).execute().body();
        System.out.println(body);
    }

    private static void goodUS(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("data_type", "JSON");
        map.put("pageSize", 20);
        map.put("page", 0);
        map.put("skuSearchType", 2);
        usToken(map, storeVO, PdApiConstants.GET_GOOD_LIST_US);
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    private static void getCarrierId(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("regionId", "211");
        usToken(map, storeVO, PdApiConstants.GET_CARRIER_LIST);
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    private static void markUpdate(PdStoreTokenVO storeVO) {
        PdMarkUpdateReq pdMarkUpdateReq = new PdMarkUpdateReq();
        pdMarkUpdateReq.setPackageSn("PK-4875146792796312929");
        pdMarkUpdateReq.setShipCompanyId("998264936");
        pdMarkUpdateReq.setTrackingNumber("92612902711813543475110561");
        Map<String, Object> map = new TreeMap<>();
        map.put("editPackageRequestList", Arrays.asList(pdMarkUpdateReq));


        usToken(map, storeVO, PdApiConstants.SHIPMENT_UPDATE);
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);

    }

    private static void price(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("pageSize", 20);
        map.put("page", 0);
        //map.put("skuSearchType", 1);
        map.put("goodsSearchType", 1);
        map.put("searchText", "603080699522795");
        //usToken(map, storeVO, PdApiConstants.GET_GOOD_LIST_US);
        usToken(map, storeVO, "bg.local.goods.list.query");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    /**
     * 如果能查到标发货信息 就走修改接口
     */
    private static void shipmentGet(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("parentOrderSn", "PO-211-18202911071351727");
        map.put("orderSn", "211-18202895342711727");
        usToken(map, storeVO, PdApiConstants.SHIPMENT_GET);
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    private static void detail(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("parentOrderSn", "PO-037-14392575073833188");

        usToken(map, storeVO, "bg.order.detail.get");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    private static void forecastUpdate(PdStoreTokenVO storeVO) {
        PdForecastDTO pdForecastDTO = new PdForecastDTO();

        pdForecastDTO.setDimensionUnit("in");
        pdForecastDTO.setHeight("0.78");
        pdForecastDTO.setWidth("8.26");
        pdForecastDTO.setLength("9.84");
        pdForecastDTO.setWeightUnit("lb");
        pdForecastDTO.setWeight("0.38");
        pdForecastDTO.setShipCompanyId("314439762");
        pdForecastDTO.setWarehouseId("WH-10037186068632929");
        pdForecastDTO.setChannelId("20313067753472");
        PdForecastDTO.Sku sku = new PdForecastDTO.Sku();
        sku.setGoodsId(601099582281206L);
        sku.setOrderSn("211-00998488108153537");
        sku.setParentOrderSn("PO-211-00998419950713537");
        sku.setQuantity(1);
        sku.setSkuId(17592471147511L);
        pdForecastDTO.setOrderSendInfoList(Arrays.asList(sku));


        Map<String, Object> map = new TreeMap<>();
        map.put("retrySendPackageRequestList", Arrays.asList(pdForecastDTO));

        usToken(map, storeVO, "bg.logistics.shipment.update");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    private static void getLabel(String url, PdStoreTokenVO storeVO) {
        System.out.println(url);
        HttpGet httpGet = new HttpGet(url);
        Map<String, Object> treeMap = new TreeMap<>();
        treeMap.put("toa-app-key", storeVO.getAppKey());
        treeMap.put("toa-access-token", storeVO.getToken());
        treeMap.put("toa-random", Func.md5Hex(UUID.randomUUID().toString()));
        Long time = System.currentTimeMillis() / 1000;
        treeMap.put("toa-timestamp", time);
        // 生成要签名的字符串
        StringBuilder signText = new StringBuilder();
        treeMap.entrySet().forEach(entry -> {
            if (isSimpleValueType(entry.getValue().getClass())) {
                signText.append(entry.getKey()).append(entry.getValue());
            } else {
                signText.append(entry.getKey()).append(JsonUtil.toJson(entry.getValue()));
            }
        });
        String s = storeVO.getAppSecret() + signText + storeVO.getAppSecret();
        for (Map.Entry<String, Object> entry : treeMap.entrySet()) {
            httpGet.setHeader(entry.getKey(), String.valueOf(entry.getValue()));
        }
        httpGet.setHeader("toa-sign", Func.md5Hex(s).toUpperCase());
        //System.out.println(httpGet.getAllHeaders());
        cn.hutool.core.io.FileUtil.writeBytes(PdHttpProxy.proxyByteWithRequest("4.242.79.188", httpGet), "C:\\Users\\ZH500\\桌面\\test\\" + System.currentTimeMillis() + ".png");
    }

    private static String getLabelUrl(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("packageSnList", Arrays.asList("PK-4253918536663192857"));

        usToken(map, storeVO, "bg.logistics.shipment.document.get");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        PdLabelResp pdLabelResp = JsonUtil.parse(resultResp, PdLabelResp.class);
        if (pdLabelResp == null) {
            throw new RuntimeException("拼多多获取物流面单信息失败：" + resultResp);
        }
        Optional<String> optional = Optional.ofNullable(pdLabelResp)
                .map(PdLabelResp::getResult)
                .map(resultBean -> resultBean.getShippingLabelUrlList())
                .map(list -> list.get(0))
                .map(PdLabelResp.ResultBean.ShippingLabelUrlListBean::getUrl);
        if (optional.isPresent()) {
            return optional.get();
        }
        throw new RuntimeException("拼多多获取物流面单信息失败：" + resultResp);
    }

    private static void getForecast(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("packageSnList", Arrays.asList("PK-5226980767171271382"));

        usToken(map, storeVO, "bg.logistics.shipment.result.get");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    //下单接口只能调一次
    //{"result":{"packageSnList":["PK-3819628637716632929"]},"success":true,"requestId":"pce09be32-5f85-4cde-b4be-51fbe10b696a","errorCode":1000000,"errorMsg":""}
    //{"success":false,"requestId":"p5263c929-d9e4-4948-ad26-6d986bb5f2b1","errorCode":20004,"errorMsg":"Order shipped"}
    private static void forecast(PdStoreTokenVO storeVO) {
        PdForecastDTO pdForecastDTO = new PdForecastDTO();

        pdForecastDTO.setDimensionUnit("in");
        pdForecastDTO.setHeight("0.78");
        pdForecastDTO.setWidth("8.26");
        pdForecastDTO.setLength("9.84");
        pdForecastDTO.setWeightUnit("lb");
        pdForecastDTO.setWeight("0.38");
        pdForecastDTO.setShipCompanyId("314439762");
        pdForecastDTO.setWarehouseId("WH-10037186068632929");
        pdForecastDTO.setChannelId("20313067753472");
        PdForecastDTO.Sku sku = new PdForecastDTO.Sku();
        sku.setGoodsId(601099582281206L);
        sku.setOrderSn("211-00998488108153537");
        sku.setParentOrderSn("PO-211-00998419950713537");
        sku.setQuantity(1);
        sku.setSkuId(17592471147511L);
//        PdForecastDTO.Sku sku2 = new PdForecastDTO.Sku();
//        sku2.setGoodsId();
//        sku2.setOrderSn();
//        sku2.setParentOrderSn();
//        sku2.setQuantity();
//        sku2.setSkuId();
//        PdForecastDTO.Sku sku3 = new PdForecastDTO.Sku();
//        sku3.setGoodsId();
//        sku3.setOrderSn();
//        sku3.setParentOrderSn();
//        sku3.setQuantity();
//        sku3.setSkuId();
        pdForecastDTO.setOrderSendInfoList(Arrays.asList(sku));

        Map<String, Object> map = new TreeMap<>();
        map.put("sendType", "0");
        map.put("sendRequestList", Arrays.asList(pdForecastDTO));
        usToken(map, storeVO, PdApiConstants.FORECAST_CREATE);
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }


    private static void usToken(Map<String, Object> map, PdStoreTokenVO storeVO, String api) {
        map.put("data_type", "JSON");
        if(US_DOMAIN.equals(storeVO.getRealDoMain())){
            map.put("access_token", storeVO.getToken());
        }else if(US_OTHER_DOMAIN.equals(storeVO.getRealDoMain())){
            map.put("access_token", ObjectUtil.isNotEmpty(storeVO.getTokenGlobal())?storeVO.getTokenGlobal():storeVO.getToken());
        }
        String sign = SignUtil.pd(map, storeVO.getAppKey(), storeVO.getAppSecret(), api);
        map.put("sign", sign);
    }


    private static String postUS(PdStoreTokenVO storeVO, String body) {
        return new PdProxyImpl().postUS(storeVO, body);
    }

    private static String getRealApiUrl(String apiUrl) {
        if (ObjectUtil.isEmpty(apiUrl)) {
            return "4.242.79.188";
        }
        int index = apiUrl.lastIndexOf("//");
        if (index < 0) {
            index = 0;
        } else {
            index += 2;
        }
        apiUrl = apiUrl.substring(index);
        return apiUrl;
    }

    private static void good(PdStoreTokenVO storeVO) {
        int page = 1;

        Map<String, Object> map = new TreeMap<>();
        map.put("pageSize", 5);
        map.put("page", page);
        //map.put("goodsSearchType", 1);
//        map.put("createdAtStart", DateUtil.addDate(new Date(),-10).getTime());
//        map.put("createdAtEnd", System.currentTimeMillis());
        //String sign = SignUtil.pd(map, "d0d421fc3ba30209b15f92c8f0eb5c2e", "656cee40abd7b3122f4159b88ecd5c1744502844", PdApiConstants.GET_GOOD_LIST);
        //String sign = SignUtil.pd(map, "d0d421fc3ba30209b15f92c8f0eb5c2e", "656cee40abd7b3122f4159b88ecd5c1744502844", "");
        //usToken(map,storeVO,PdApiConstants.GET_GOOD_LIST);
        cnToken(map, storeVO, PdApiConstants.GET_GOOD_LIST);
        String body = HttpRequest.post(CN_URL).body(JsonUtil.toJson(map)).execute().body();
        page++;
        System.out.println(body);


    }

    private static void goodSku(PdStoreTokenVO storeVO) {
        int page = 0;
        Map<String, Object> map = new TreeMap<>();
        map.put("pageSize", 100);
        map.put("page", page);
        map.put("skuSearchType", 2);
        map.put("searchText", "602629191112478");
//        map.put("createdAtStart", DateUtil.addDate(new Date(),-10).getTime());
//        map.put("createdAtEnd", System.currentTimeMillis());
        //usToken(map, storeVO, PdApiConstants.GET_GOOD_LIST);
        usToken(map, storeVO, "bg.local.goods.sku.list.query");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    private static void warehouse(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        usToken(map, storeVO, "bg.logistics.warehouse.list.get");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);
    }

    private static void optimize(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("warehouseId", "WH-07546107658391233");
        map.put("orderSnList", Arrays.asList("211-08362823516712520","211-08362823516712520"));
//        map.put("extendWeight", "17");
//        map.put("extendWeightUnit", "oz");
        map.put("weight", "0.1");
        map.put("weightUnit", "lb");
        map.put("length", "21.65");
        map.put("width", "2.62");
        map.put("height", "2.62");
        map.put("dimensionUnit", "in");
        usToken(map, storeVO, "bg.logistics.shippingservices.get");
        String resultResp = postUS(storeVO, JsonUtil.toJson(map));
        System.out.println(resultResp);

    }

    private static void methodSign2(PdStoreTokenVO storeVO) {
//        PdMarkProxyDTO dto = new PdMarkProxyDTO();
//        dto.setCarrierId("960246690");
//        dto.setOrderNumber("PO-211-17984746583670979");
//        dto.setTrackingNumber("9200190356641451351140");
//        List<PdMarkProxyDTO.Sku> skuList = new ArrayList<>();
//        PdMarkProxyDTO.Sku one = new PdMarkProxyDTO.Sku();
//        one.setGoodsId(601099573310911L);
//        one.setOrderSn("211-09528587233913892");
//        one.setQuantity(1);
//        one.setSkuId(17592440144636L);
//        skuList.add(one);
//        dto.setSkuList(skuList);
//
//        PdMarkSendReq pdMarkSendReq = new PdMarkSendReq();
//        pdMarkSendReq.setCarrierId(Integer.valueOf(dto.getCarrierId()));
//        pdMarkSendReq.setTrackingNumber(dto.getTrackingNumber());
//
//        List<PdMarkSendReq.OrderSendInfoListBean> sendInfoListBeans = dto.getSkuList().stream().map(sku -> {
//            PdMarkSendReq.OrderSendInfoListBean sendInfoListBean = new PdMarkSendReq.OrderSendInfoListBean();
//            sendInfoListBean.setGoodsId(sku.getGoodsId());
//            sendInfoListBean.setOrderSn(sku.getOrderSn());
//            sendInfoListBean.setParentOrderSn(dto.getOrderNumber());
//            sendInfoListBean.setQuantity(sku.getQuantity());
//            sendInfoListBean.setSkuId(sku.getSkuId());
//            return sendInfoListBean;
//        }).collect(Collectors.toList());
//
//        pdMarkSendReq.setOrderSendInfoList(sendInfoListBeans);
        String req = "[\n" +
                "\t{\n" +
                "\t\t\"carrierId\": 998264936,\n" +
                "\t\t\"trackingNumber\": \"92612903032501543409822518\",\n" +
                "\t\t\"orderSendInfoList\": [\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"quantity\": 1,\n" +
                "\t\t\t\t\"orderSn\": \"211-01685095178872133\",\n" +
                "\t\t\t\t\"parentOrderSn\": \"PO-211-01685089935992133\",\n" +
                "\t\t\t\t\"goodsId\": 601100084059518,\n" +
                "\t\t\t\t\"skuId\": 17594643136652\n" +
                "\t\t\t}\n" +
                "\t\t]\n" +
                "\t}\n" +
                "]";
        List<PdMarkSendReq> pdMarkSendReqs = JsonUtil.parseArray(req, PdMarkSendReq.class);
        PdMarkSendReq pdMarkSendReq = pdMarkSendReqs.get(0);
        pdMarkSendReq.setSelfShippingWarehouseId("WH-00448638750870024");
        Map<String, Object> map = new TreeMap<>();
        map.put("sendType", "0");
        map.put("sendRequestList", JsonUtil.toJson(pdMarkSendReqs));
        usToken(map, storeVO, PdApiConstants.SHIP_ORDER);
        System.out.println(postUS(storeVO, JsonUtil.toJson(map)));
    }


    private static void getSignCompany(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("regionId", "37");
        usToken(map, storeVO, "bg.logistics.companies.get");
        System.out.println(postUS(storeVO, JsonUtil.toJson(map)));
    }

    private static void orderList(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("pageNumber", "1");
        map.put("pageSize", "100");
        map.put("updateAtStart", DateUtil.addDay(new Date(), -3).getTime() / 1000);
        map.put("updateAtEnd", DateUtil.addDay(new Date(), 0).getTime() / 1000);
        map.put("data_type", "JSON");
        //map.put("parentOrderSnList", JsonUtil.toJson(Arrays.asList("PO-037-14392575073833188")));//最多20个
        usToken(map, storeVO, "bg.order.list.get");
        System.out.println(postUS(storeVO, JsonUtil.toJson(map)));
    }

    private static void receiver(PdStoreTokenVO storeVO) {
        Map<String, Object> map = new TreeMap<>();
        map.put("parentOrderSn", "PO-211-21283293061672276");
        usToken(map, storeVO, "bg.order.shippinginfo.v2.get");
        System.out.println(postUS(storeVO, JsonUtil.toJson(map)));
    }

    private static void cnToken(Map<String, Object> map, PdStoreTokenVO storeVO, String api) {
        map.put("data_type", "JSON");
        map.put("access_token", storeVO.getTokenCn());
        String sign = SignUtil.pd(map, storeVO.getAppKeyCn(), storeVO.getAppSecretCn(), api);
        map.put("sign", sign);
    }
}
